package com.junqson.je.recruit.controller;

import com.junqson.je.common.annotation.LoginRequire;
import com.junqson.je.common.model.ApiResult;
import com.junqson.je.recruit.service.ApplicationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Descriptions
 * @Company
 * @Author Junqson
 * @Date 2020/2/5 21:20
 * @Version 1.0
 */
@Slf4j
@RestController
@RequestMapping("apply")
public class ApplicationController {


    @Autowired
    ApplicationService applicationService;


    /**
     * 投递职位
     */
    @LoginRequire
    @RequestMapping("job")
    public ApiResult applyJob(Integer jobId) {
        if (jobId == null) {
            return ApiResult.error("job id is null");
        }
        return applicationService.applyJob(jobId);
    }


    /**
     * 是否已经投递
     */
    @LoginRequire
    @RequestMapping("applied")
    public ApiResult hasApplied(Integer jobId) {
        if (jobId == null) {
            return ApiResult.error("job id is null");
        }
        return ApiResult.success(applicationService.hasApplied(jobId));
    }

    /**
     * 查看个人投递记录
     */
    @LoginRequire
    @RequestMapping("pagePersonal")
    public ApiResult personalApplications(Integer page, Integer size) {
        return ApiResult.success(applicationService.pagePersonalApplications(page, size));
    }


    /**
     * 查看职位下的投递记录
     */
    @LoginRequire(needAuth = true)
    @RequestMapping("pageJobApplications")
    public ApiResult pageJobApplications(Integer jobId, Integer page, Integer size) {
        if (jobId == null) {
            return ApiResult.error("job id is null");
        }
        return ApiResult.success(applicationService.pageJobApplications(jobId, page, size));
    }


    /**
     * 查看发布的所有职位的投递记录
     */
    @LoginRequire(needAuth = true)
    @RequestMapping("pageAllApplications")
    public ApiResult pageAllApplications(Integer page, Integer size) {
        return ApiResult.success(applicationService.pageAllJobApplications(page, size));
    }

    /**
     * 完成投递过程
     */
    @LoginRequire(needAuth = true)
    @RequestMapping("complete")
    public ApiResult completeApplications(Integer applicationId) {
        if (applicationId == null) {
            return ApiResult.error("application id is null");
        }
        applicationService.completeApplication(applicationId);
        return ApiResult.success();

    }

    /**
     * 拒绝该投递
     */
    @LoginRequire(needAuth = true)
    @RequestMapping("reject")
    public ApiResult rejectApplications(Integer applicationId) {
        if (applicationId == null) {
            return ApiResult.error("application id is null");
        }
        applicationService.rejectApplication(applicationId);
        return ApiResult.success();
    }

    /**
     * 根据投递记录查看简历
     */
    @LoginRequire(needAuth = true)
    @RequestMapping("resume")
    public ApiResult checkResumeOfApplication(Integer applicationId) {
        if (applicationId == null) {
            return ApiResult.error("application id is null");
        }
        return ApiResult.success(applicationService.getResumeOfApplication(applicationId));
    }
}

